package com.feifei.controller;

import com.feifei.bean.Repay;
import com.feifei.service.RepayService;
import com.feifei.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@CrossOrigin
@Controller
public class RepayController {
    @Autowired
    RepayService repayService;

    @ResponseBody
    @RequestMapping("/repay/addRepay")
    public Result addRepay(@RequestBody Repay repay) {
        Result result = new Result();
        if(repay.getId()==null&&repay.getId()==0){
            //执行添加回报操作
            int i = repayService.addRepay(repay);
            if (i > 0) {
                result.setStatus(true);
                result.setMsg("success");
                return result;
            }
        }else{
            //执行更新操作
           int i= repayService.editRepay(repay);
            if (i > 0) {
                result.setStatus(true);
                result.setMsg("success");
                return result;
            }
        }
        result.setStatus(false);
        result.setMsg("false");
        return result;
    }

    //根据项目id获取回报
    @ResponseBody
    @RequestMapping("/repay/getRepayByProductId")
    public Result getRepayByProductId(Integer productId) {
        Result result = new Result();
         Repay repay=  repayService.getRepayByProductId(productId);
         if(repay!=null){
             result.setStatus(true);
             result.setMsg("根据项目id查询回报成功");
             result.setData(repay);
         }else{
             result.setStatus(false);
             result.setMsg("根据项目id查询回报失败");
         }
        return result;

    }

}
